package com.ruoyi.milktea.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.milktea.domain.ShopCommodity;
import com.ruoyi.milktea.service.IShopCommodityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 栏目管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-06
 */
@RestController
@RequestMapping("/milktea/commodity")
public class ShopCommodityController extends BaseController
{
    @Autowired
    private IShopCommodityService shopCommodityService;

    /**
     * 查询栏目管理列表
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ShopCommodity shopCommodity)
    {
        startPage();
        List<ShopCommodity> list = shopCommodityService.selectShopCommodityList(shopCommodity);
        return getDataTable(list);
    }

    /**
     * 导出栏目管理列表
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:export')")
    @Log(title = "栏目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ShopCommodity shopCommodity)
    {
        List<ShopCommodity> list = shopCommodityService.selectShopCommodityList(shopCommodity);
        ExcelUtil<ShopCommodity> util = new ExcelUtil<ShopCommodity>(ShopCommodity.class);
        util.exportExcel(response, list, "栏目管理数据");
    }

    /**
     * 获取栏目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(shopCommodityService.selectShopCommodityById(id));
    }

    /**
     * 新增栏目管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:add')")
    @Log(title = "栏目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ShopCommodity shopCommodity)
    {
        return toAjax(shopCommodityService.insertShopCommodity(shopCommodity));
    }

    /**
     * 修改栏目管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:edit')")
    @Log(title = "栏目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopCommodity shopCommodity)
    {
        return toAjax(shopCommodityService.updateShopCommodity(shopCommodity));
    }

    /**
     * 删除栏目管理
     */
    @PreAuthorize("@ss.hasPermi('milktea:commodity:remove')")
    @Log(title = "栏目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(shopCommodityService.deleteShopCommodityByIds(ids));
    }
}
